<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="template">
<head th:replace="fragments/head::head"></head>
<body>
<th:block layout:fragment="content">

    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h4>物料父件新增</h4>
                        <div class="ibox-tools">
                        </div>
                    </div>
                    <div class="ibox-content">
                        <form class="form-horizontal m-t">
                            <!--父件基本信息-->
                            <div class="panel-title">
		                        <h5 style="color:#293846;">父件信息</h5>
		                    </div>
		                    
		                    <input type="hidden" skey="materialInfoId" id="materialInfoId" readOnly="true" class="form-control formSubmit">
		                    
		                   	<!-- 按钮插件样式 -->
                            <div class="form-group">
                                <label class="col-sm-1 control-label">父件编码：</label>
                                <div class="col-sm-2">
                                	<div class="input-group">
                                         <input type="text" skey="coding" id="coding" readOnly="true" class="form-control formSubmit">  <span class="input-group-btn"> <input type="button" class="btn btn-primary " data-toggle="modal" data-target="#myModal" value="查找"></input>
                                         </span>
                                    </div>
                                    <!-- <input type="text" class="form-control formSubmit" skey="materialCoding" emsg="物料编码不能为空"> -->
                                </div>
                                <label class="col-sm-1 control-label">父件名称：</label>
                                <div class="col-sm-2">
                                    <div class="input-group">
                                         <input type="text" skey="name" id="name" readOnly="true" class="form-control formSubmit">  <span class="input-group-btn"> <input type="button" class="btn btn-primary " data-toggle="modal" data-target="#myModal" value="查找"></input>
                                         </span>
                                    </div>
                                </div>
                                <label class="col-sm-1 control-label">规格：</label>
                                <div class="col-sm-2">
                                    <input type="text" class="form-control formSubmit" skey="spec" id='spec' readOnly="true">
                                </div>
                                <label class="col-sm-1 control-label">级次：</label>
	                            <div class="col-sm-2">
	                                <input type="number" class="form-control formSubmit" skey="level" id="level" readOnly="true" value='0'>
	                            </div>
                            </div>
                            <!--物料设置-->
                            <div class="form-group">
                                <label class="col-sm-1 control-label">版本号：</label>
                                <div class="col-sm-2">
                                    <input type="text" class="form-control formSubmit" skey="version" emsg="版本号不能为空">
                                </div>
                                <label class="col-sm-1 control-label">计量单位：</label>
                                <div class="col-sm-2">
                                 <input type="text" class="form-control formSubmit" skey="measurementUName" id='measurementUName' readOnly="true">
                                 <input type="hidden" skey="measurementUId" id='measurementUId' >
                                    <!-- <select class="form-control input-sm formSubmit" skey="measurementUId" >
                                        <option th:each="menuOne:${unitList}" th:value="${menuOne.id}" th:text="${menuOne.name}"></option>
                                    </select> -->
                                </div>
                                <label class="col-sm-1 control-label">是否停用：</label>
                                <div class="col-sm-2">
                                    <select class="form-control input-sm formSubmit" skey="isNoUsed">
                                        <option value="0" selected = "selected" >否</option>
                                        <option value="1">是</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                            <label class="col-sm-1 control-label">是否默认BOM：</label>
                             <div class="col-sm-2">
                                 <select class="form-control input-sm formSubmit" skey="isDefault">
                                     <option value="0" >否</option>
                                     <option value="1" selected = "true" >是</option>
                                 </select>
                             </div>
                            </div> 
                            <div class="form-group">
                                <label class="col-sm-1 control-label">备注：</label>
                                <div class="col-sm-11">
                                    <input name="remark"  class="form-control formSubmit" skey="remark" id="remark">
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-3">
                                    <button class="btn btn-primary" type="button" onclick="saveMenu()">保存</button>
                                    <button class="btn btn-primary" type="button" onclick="history.go(-1);">返回</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
	<!-- 弹出层 -->    
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
        <div class="modal-dialog" style="width:1100px;height:600px">
            <div class="modal-content">
            	<!-- 弹出层头部 -->
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">父件选择</h4>
                </div>
                <!-- 弹出层内容 -->
                <div class="modal-body">
                   <div class="hr-line-dashed m-t-sm m-b-sm"></div>
                   <div style="width:1000px;overflow-x:scroll;">
		            <table id="callbackgrid" ></table> 
		            <div id="callbackpager" ></div> 
		           </div>
                </div>
                <!-- 弹出层尾部 -->
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>

    <!--<div th:replace="/department/model::modelDiv"></div>-->
    <js th:replace="/eng/bom/add/businessJs::businessJs"></js>
     <script>
     $(document).ready(function(){
    	 $(function(){ 
         	pageInit(); 
         }); 
         function pageInit(){ 
         	var lastsel; 
         	 jQuery("#callbackgrid").jqGrid( {
         		//初始化页面时加载数据
         		url : '/eng/material/info/data', 
         		//数据传输解析格式设置
         		datatype : "json", 
         		//页面加载样式
         		styleUI: 'Bootstrap',
         		//表头列名称
         		colNames : [ '存货ID','所属公司','物料编码','物料名称','物料规格','品牌','物料类型','计量单位',
                             '计价方式','是否停用','是否可销售','是否外购','是否生产耗用','是否虚拟件','是否委外','现存量',
                             '可用量','最小包装量','图片','创建人','创建日期','备注'], 
         		//列模型属性配置
         		colModel : [ 
					{name: 'id',index: 'id',hidden:true },
					{name: 'companyId',index: 'companyId',hidden:true},
					{name: 'materialCoding',index: 'materialCoding'},
					{name: 'materialName',index: 'materialName'},
					{name: 'materialSpec',index: 'materialSpec'},
					{name: 'brandId',index: 'brandId',hidden:true},
					{name: 'materialTypeId',index: 'materialTypeId',hidden:true},
					{name: 'measurementUId',index: 'measurementUId'},
					{name: 'materialPriceTypeId',index: 'materialPriceTypeId',hidden:true},
					{name: 'isNoUsed',index: 'isNoUsed',
						//渲染
         				formatter: function (value, grid, rows, state) { 
         					if (value == "false" || !value)
        				        return '<span style="color:red;">X</span>';
        				    else
        				        return '<span style="color:green;">√</span>'; 
         					}
						},
					{name: 'isSale',index: 'isSale'},
					{name: 'isBuy',index: 'isBuy'},
					//是否生产耗用
					{name: 'isProdConsumption',index: 'isProdConsumption'},
					{name: 'isVirtual',index: 'isVirtual'},
					{name: 'isOutsource',index: 'isOutsource'},
					{name: 'onHandQuantity',index: 'onHandQuantity'},
					{name: 'availableQuantity',index: 'availableQuantity'},
					{name: 'minimumPackingQuantity',index: 'minimumPackingQuantity'},
					/* {name: 'cumulative_stock'},
					{name: 'cumulative_return','defaultContent':''},
					{name: 'cumulative_shipments','defaultContent':''},
					{name: 'cumulative_withdrawal','defaultContent':''}, */
					{name: 'pictureAddr',index: 'pictureAddr'},
					{name: 'creatorId',index: 'creatorId'},
					{name: 'ctime',index: 'ctime'},
					{name: 'remark',index: 'remark'}
         			],
         		//表格自适应宽度
         		autoWidth:true,
         		shrinkToFit: true,
         		//width:1000, 
         		//autoScroll: true,
             	height: 350,
         		//每页显示的条数
         		rowNum : 10,
         		//配置分页显示信息
         		rowList : [ 10, 20, 30 ], 
         		//绑定分页工具栏
         		pager : '#callbackpager', 
         		//用数组展示 可排序列
         		sortname : 'id', 
         		//显示当前网格数据条数
         		viewrecords : true, 
         		//排序方式 
         		sortorder : "desc", 
         		//multiselect: true,
         		altRows: true,  
                 rownumbers: true,
         		//编辑完成后向台提交
         		editurl : "/RowEditing", 
         		//网格标题
         		caption : "物料清单",
         		//网格双击事件
         		ondblClickRow: function (id){  
         			//id为当前行的 index
         			var rowData = $("#callbackgrid").jqGrid("getRowData",id);
         			//回填网格 父件编码
         			$("#coding").val(rowData.materialCoding); 
         			//回填父件名称
         			$("#name").val(rowData.materialName); 
         			//回填规格型号
         			$("#spec").val(rowData.materialSpec);
         			//设置计量单位id
         			$("#measurementUId").val(rowData.measurementUId);
         			//设置计量单位名称
         			$("#measurementUName").val(rowData.measurementUId);
         			
         			$("#myModal").modal('hide');
         		}
         	}); 
         	// 配置jqgrid 下方的导航信息
         	jQuery("#callbackgrid").jqGrid('navGrid', "#callbackpager", { edit : false, add : false, del : true, position: "left" },{},{},{},{multipleSearch:true});  
         	//下方为  官方API 示例  http://blog.mn886.net/jqGrid/
         	 //$("#callbackgrid").closest(".ui-jqgrid-bdiv").css({ 'overflow-x' : 'scroll' });
         };
    	 }); 
     </script>
</th:block>
</body>
</html>